<template>
	<el-dialog :title="dialogTitle" :visible.sync="visible" top="0" width="560px" append-to-body>
		<el-form v-bind="formConfig" :model="formData" :rules="formRules" label-width="84px">
			<el-row :gutter="16" v-loading="loading">
				<el-col :span="24">
					<el-form-item label="字典名称" prop="content">
						<el-input v-model="formData.content"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="字典编码" prop="code">
						<el-input v-model="formData.code"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="字典描述">
						<el-input type="textarea" v-model="formData.name"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="15">
					<el-form-item label="字典类型" prop="type">
						<el-radio-group v-model="formData.type">
							<el-radio label="1">枚举</el-radio>
							<el-radio label="2">常量</el-radio>
						</el-radio-group>
					</el-form-item>
				</el-col>
				<el-col :span="9">
					<el-form-item label="是否可配置" label-width="90px">
						<el-switch v-model="formData.isConfig" active-value="1" inactive-value="2"></el-switch>
					</el-form-item>
				</el-col>
				<el-col :span="24" v-if="formData.isConfig === '1'">
					<el-form-item label="显示配置">
						<dict-config v-model="formData.configJson"></dict-config>
					</el-form-item>
				</el-col>
			</el-row>
		</el-form>
		<template slot="footer">
			<el-button size="medium" @click="visible = false">取消</el-button>
			<el-button size="medium" type="primary" :loading="btnLoading" @click="handleSubmitForm()">{{ formTypeName }}</el-button>
		</template>
	</el-dialog>
</template>

<script>
import dictConfig from './config';
import formMixins from '@/mixins/formMixins';
import { queryDictDefine, addedDictDefine, updateDictDefine } from '@/api/system/tbSysDictDefinition';
export default {
	mixins: [formMixins],
	components: { dictConfig },
	props: {
		type: { type: String, default: '' }
	},
	data() {
		return {
			formName: '角色',
			formRules: {
				content: [{ required: true, message: '请输入字典名称', trigger: 'blur' }],
				code: [{ required: true, message: '请输入字典编码', trigger: 'blur' }],
				type: [{ required: true, message: '请选择字典类型', trigger: 'change' }]
			},
			btnLoading: false
		};
	},
	computed: {
		detailData() {
			return eval(queryDictDefine);
		},
		callFunction() {
			return eval(this.addOrEdit ? addedDictDefine : updateDictDefine);
		}
	},
	methods: {
		formatFormParams(data) {
			this.$set(this.formData, 'type', this.addOrEdit ? this.type : data.type);
		}
	}
};
</script>

<style lang="scss" scoped>
.dict_form_wrapper {
	width: 100%;
	padding: 10px 6px 0 0;
	box-sizing: border-box;
}

.show_type_switch {
	display: flex;
	align-items: center;
	margin-top: 10px;

	dl {
		display: flex;
		flex: 1;
		overflow: hidden;
	}

	dt {
		flex-shrink: 0;
	}

	dd {
		width: 100px;
	}
}

:deep(.show_type_option) {
	width: 100%;
	clear: both;
	margin-top: 10px;

	dl {
		display: flex;
		border: solid 1px #dcdfe6;
		border-top: none;

		&:first-child {
			border-top: solid 1px #dcdfe6;
		}
	}

	dt {
		flex: 1;
	}

	dd {
		flex-shrink: 0;
		border-left: solid 1px #dcdfe6;
		text-align: center;

		&.val {
			width: 80px;
		}

		&.upload {
			width: 80px;
		}

		&.btn {
			width: 50px;
		}
	}

	.el-input {
	}

	.el-input__inner {
		border: none;
		border-radius: 0;
	}
}
</style>
